// Card.h: interface for the CCard class.
//
//////////////////////////////////////////////////////////////////////

#ifndef __CARD_H__
#define __CARD_H__
#include "iface.h"


class CCard : CIface
{
public:

    enum Value {
        Ace 	= CARD_INDEX_ACE,
        King 	= CARD_INDEX_KING,
        Queen 	= CARD_INDEX_QUEEN,
        Jacke 	= CARD_INDEX_JACKE,
        Ten 	= CARD_INDEX_TEN,
        Nine 	= CARD_INDEX_NINE,
        Eight 	= CARD_INDEX_EIGHT,
        Seven 	= CARD_INDEX_SEVEN,    
        Six 	= CARD_INDEX_SIX,
        Five 	= CARD_INDEX_FIVE,
        Four 	= CARD_INDEX_FOUR,
        Three 	= CARD_INDEX_THREE,
        Two  	= CARD_INDEX_TWO,
		UnknownValue	};

     enum Suit {
          Diamonds 	= CARD_INDEX_DIAMONDS,
          Hearts 	= CARD_INDEX_HEARTS,
          Clubs 	= CARD_INDEX_CLUBS,
          Spades	= CARD_INDEX_SPADES,
		  UnknownSuit
       };
    enum Color {
          Red,
          Black
       };

	void Draw(unsigned int _x, unsigned int _y, bool draw_selected = false, unsigned char _width = 0, unsigned char _height = 0  );
	bool IsValid() const { if( value != UnknownValue and suit != UnknownSuit ) return true; return false; };

    static Suit SuitFromIndex( unsigned char _suit )
    {
        switch(_suit)
        {
            case 0: return Diamonds; 
            case 1: return Hearts; 
            case 2: return Clubs; 
            case 3: return Spades; 
            default: throw "Wrong suit index";
        }
    }

    static Value ValueFromIndex( unsigned char _value )
    {
        switch(_value)
        {
            case 0: return Ace; 
            case 1: return King; 
            case 2: return Queen; 
            case 3: return Jacke; 
            case 4: return Ten; 
            case 5: return Nine; 
            case 6: return Eight; 
            case 7: return Seven; 
            case 8: return Six; 
            case 9: return Five; 
            case 10: return Four; 
            case 11: return Three; 
            case 12: return Two; 
            default: throw "Wrong suit index";
        }
    }

	CCard::CCard( const CCard& _card );
	
    CCard()
    {
		this->value = UnknownValue;
		this->suit = UnknownSuit;
		//std::cout << inf << "default CCard constructor" << std::endl;
    }

	/*
	CCard( unsigned char _suit, unsigned char _value, bool _face_down = true )
	{
		std::cout << inf << "CCard(" << (int)_suit << "," << (int)_value << ")" << std::endl;

        Value   value = ValueFromIndex( _value );
        Suit    suit = SuitFromIndex( _suit );

        CCard( suit, value, _face_down );
	}
	*/

	CCard( Suit _suit, Value _value, bool _face_down = true )
	{
		//std::cout << inf << "CCard(" << (int)_suit << "," << (int)_value << ")" << std::endl;
		this->SetValue( _value );
		this->SetSuit( _suit );
		this->face_down = _face_down;
	}

	virtual ~CCard();

	void SetSuit( Suit _suit ) { suit = _suit; }
	Suit GetSuit( ) const { return suit; }

    static Color GetColor( Suit _suit )
    {
            switch( _suit )
            {
                case Diamonds:  return Red;
                case Hearts:    return Red;
                case Clubs:     return Black;
                case Spades:    return Black;
				default: throw "CCard::GetColor: Unknown Suit";
            };
    }

	static void CCard::DrawCursor( unsigned int _x, unsigned int _y );
	static void CCard::DrawPlaceHolder( unsigned int _x, unsigned int _y );	
	
     Color  GetColor() const
    {
            return GetColor( this->suit );
    }

	void SetValue( Value _value ) { value = _value; }
	Value GetValue( ) const { return value; }

	int	CompareValue( const CCard& _card );
	
    
    static void  SetTrump( Suit _suit ) { trump = _suit; }
    static Suit  GetTrump() { return trump; }

private:

	Suit	        suit;
	Value       	value;
	bool		    face_down;

    static Suit     trump;


public:
	bool IsFaceDown() const;
	bool Flip();
};

#endif // __CARD_H__
